SELECT DISTINCT(MediaID) FROM (SELECT MasterMedia.MediaID, MasterMedia.AccountID AS MediaAccountID, MediaTypeID, IsPublished FROM MasterMedia WHERE MediaID NOT IN (SELECT MediaID FROM MasterMediaAudienceList) ) AS Table1 WHERE IsPublished = 1 and MediaTypeID = 1 and MediaAccountID = ORDER BY MediaID DESC LIMIT 0,10 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY MediaID DESC LIMIT 0,10' at line 1